package com.sc.app;

import java.io.Serializable;

import com.sc.webview.LoadWebView;
import com.sc.webview.WebViewMain;

import android.os.Bundle;
import android.app.Activity;
import android.app.SearchManager;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener , Serializable{

	private static final long serialVersionUID = 1L;
	
	private Button button;
	private Button btn1;
	private Button btn2;
	public EditText editText;
	public EditText msg;
	private static final String TAG = "MainActivityLOG";
	private static final String ACTION_WEB_SEARCH = "android.intent.action.WEB_SEARCH";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.i(TAG, "onCreate");
        button = (Button) findViewById(R.id.toAnother);
        button.setOnClickListener(this);
    }
    
    @Override
    protected void onStart() {
    	// TODO Auto-generated method stub
    	super.onStart();
    	Log.i(TAG, "onStart");
    }
    
    @Override
    protected void onResume() {
    	// TODO Auto-generated method stub
    	super.onResume();
    	intentDemo();
    	Log.i(TAG, "onResume");
    	
    	
    }
    
    @Override
    protected void onPause() {
    	// TODO Auto-generated method stub
    	super.onPause();
    	Log.i(TAG, "onPause");
    }
    
    @Override
    protected void onStop() {
    	// TODO Auto-generated method stub
    	super.onStop();
    	Log.i(TAG, "onStop");
    }
    
    @Override
    protected void onDestroy() {
    	// TODO Auto-generated method stub
    	super.onDestroy();
    	Log.i(TAG, "onDestroy");
    }
    
    
    private void intentDemo(){
    	btn1 = (Button) findViewById(R.id.btn1);
    	btn2 = (Button) findViewById(R.id.btn2);
    	btn1.setOnClickListener(MainActivity.this);
    	btn2.setOnClickListener(MainActivity.this);
    }

	@Override
	public void onClick(View view) {
		// TODO Auto-generated method stub
		switch (view.getId()) {
		case R.id.btn1:
				btn1Fn();
			break;
		case R.id.btn2:
				btn2Fn();
			break;
		case R.id.toAnother:
				newActivity();
			break;
		
		}
	}
	private void newActivity() {
		// TODO Auto-generated method stub		
		Intent intent = new Intent(MainActivity.this,second_main.class);
		startActivity(intent);
	}

	
	private void btn1Fn() {
		// TODO Click To Open WebBroswer 
		editText = (EditText) findViewById(R.id.messageText);
		msg = (EditText) findViewById(R.id.msg);
		String searchKeyword = editText.getText().toString();		
		Intent intent = new Intent(ACTION_WEB_SEARCH);
		Bundle bundle = new Bundle();
		if(null != searchKeyword && !"".equals(searchKeyword)){
			bundle.putString("key", searchKeyword);
			intent.putExtra(SearchManager.QUERY, bundle.getString("key"));
			startActivity(intent);
		}else{
			msg.requestFocus();
			Toast.makeText(MainActivity.this, "KeyWord Is Null", Toast.LENGTH_SHORT).show();
		}
		
		//Toast.makeText(MainActivity.this, "Btn1", Toast.LENGTH_SHORT).show();
	}
	
	private void btn2Fn() {
		// TODO Auto-generated method stub
		Intent intent = new Intent(MainActivity.this,LoadWebView.class);
		startActivity(intent);
	}
}
